import React,{Component} from "react";
import {BrowserRouter as Router,Route,Switch,Redirect} from "react-router-dom";

//https://www.cnblogs.com/jiangyang/p/4519648.html
//https://www.zhangxinxu.com/study/201109/html5-file-image-ajax-upload.html

//https://apps.ixingban.com/fanscourse/?accessToken=s5cBM0fZLaC_AlpNmEo4fhNx-akdc-is15BclGAkvxXoTvigDCx4z3ehlhsVkKuKAq0KPRFMML2r5uv71byX7g

//磨刀
//https://org.modao.cc/app/64090f6b9c8646e12516ab13b6c448e188eccb9a?simulator_type=outside_artboard&sticky#screen=s01D3C9C2091591581657497

//设计图链接
//https://lanhuapp.com/web/#/item/project/board?type=share_mark&pid=153698a5-e9fe-4b25-b05a-3fcdc69110a7&activeSectionId=&teamId=e71f24c8-460e-443d-89b8-a12ab66c3e7b&param=c5de9db9-cd6c-4c37-8b33-a0a2ea8911f9

//接口文档
//https://documenter.getpostman.com/view/573334/SzzdDMSw?version=latest

//选择多张图片
//https://blog.csdn.net/weixin_42225141/article/details/80343812


import config from "./api/config"
import axios from "axios"

import Index from "./pages/index"
import User from "./pages/user"
import Edit from "./pages/edit"
import Postwork from "./pages/postwork"

import Bindphone from "./pages/bindphone"

import LoginAdmin from "./pages/loginadmin"

import RankList from "./pages/ranklist"
import RankAdmin from "./pages/rankadmin"
import CourseList from "./pages/courselist"
import CourseAdmin from "./pages/courseadmin"
import Detail from "./pages/detail"
import Workdetail from "./pages/workdetail"
import Assignments from "./pages/assignments"



const routes = [
    {path:"/fanscourse/loginadmin",component:LoginAdmin},
    {path:"/fanscourse/edit",component:Edit},
    {path:"/fanscourse/courselist",component:CourseList},
    {path:"/fanscourse/postwork/:id",component:Postwork},
    {path:"/fanscourse/bindphone",component:Bindphone},
    {path:"/fanscourse/courseadmin/:id",component:CourseAdmin},
    {path:"/fanscourse/ranklist",component:RankList},
    {path:"/fanscourse/rankadmin/:id",component:RankAdmin},
    {path:"/fanscourse/user",component:User},
    {path:"/fanscourse/assignments/:id",component:Assignments},
    {path:"/fanscourse/detail/:id",component:Detail},
    {path:"/fanscourse/workdetail/:id",component:Workdetail},
    {path:"/fanscourse/",component:Index}
]


function JixiuAuthorize() {

    var accessToken = window.queryString('accessToken');

    // jixiu app
    if (accessToken) {
            
        var url = 'https://www.jixiuapp.com/api/Core/v200/appUser/Get?appKey=qdPxHSIwsuU0WOGe8m2IhIFzcYet37eSqg0E7NIzcVEOKqfKVdvHqb5Jkc1M9aV_G_5362_YnJ4SR-LIaX17og&accessToken=' + accessToken;
        
        return new Promise(function(resolve,reject){
            window.$.ajax({
                   url: url,
                   contentType: "application/json; charset=utf-8",
                   type: "GET",
                   async: true,
                   crossDomain: true,
                   dataType: 'json'
            }).then(function (data) {
                data.AccessToken = accessToken;
                resolve(data);
                window.location.href="https://apps.ixingban.com/fanscourse";
               //localStorage.setItem("worksawardUserinfo", JSON.stringify(data));
                
            }).catch(function (err) {
                reject(JSON.stringify(err))
              //alert(JSON.stringify(err));
            });
        })
        
    }
}


/*function addUser(platform,openID,avator,nickName){
  var data = JSON.stringify({
     "campaignGameID": 378,
     "openID": openID,
     "platform": platform,  //1:微信,2:微博,4:QQ
     "avator": avator,
     "nickName": nickName
  });

    var xhr = new XMLHttpRequest();


    xhr.addEventListener("readystatechange", function () {
      if (this.readyState === 4) {
        console.log(this.responseText);
      }
    });

    xhr.open("POST", "https://game.jixiucloud.cn/api/CampaignGameUsers");
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.setRequestHeader("Content-Length", "105");
    xhr.setRequestHeader("Connection", "keep-alive");
    xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
    xhr.setRequestHeader("cache-control", "no-cache");
    xhr.send(data);
}*/




class App extends Component{

    async componentWillMount(){

        if(window.queryString('accessToken')){
            let data = await JixiuAuthorize();
            localStorage.setItem("courseUserinfo", JSON.stringify(data));
            //localStorage.setItem("IsJixiu",true);
        }
    }

    render(){
      return(
          <div className="app">
              <Router>
                  <Switch>
                      {routes.map(item=>{
                          return <Route path={item.path} component={item.component} key={item.path}/>
                      })}
                     
                  </Switch>
              </Router>   
          </div>
		  )
	  }
}



export default App;                    